package com.starling.extend.components
{
	import feathers.controls.TextInput;
	import feathers.core.FeathersControl;
	import feathers.core.IFeathersControl;
	import feathers.core.IFocusDisplayObject;
	import feathers.core.ITextEditor;
	import feathers.core.ITextRenderer;
	import feathers.core.IValidating;
	import feathers.core.PropertyProxy;
	import feathers.events.FeathersEventType;
	import feathers.skins.StateValueSelector;
	
	import starling.core.Starling;
	
	public class BTextInput extends TextInput
	{
		private var _style:Object;
		
		public function BTextInput()
		{
			super();
			
		}
		
		public function get style():Object {return _style;}
		public function set style(value:Object):void
		{
			_style = value;
			
			setSize(value.width ,value.height);
			//
			text = value.text;
			textEditorProperties.border = value.border;
			textEditorProperties.textAlign = value.align;
			textEditorProperties.bold = value.bold;
			//textEditorProperties.fontName = value.font;
			textEditorProperties.fontFamily = value.font;
			textEditorProperties.color = value.color;
			textEditorProperties.fontSize = value.size;
			textEditorProperties.underline = value.underline;
			textEditorProperties.italic = value.italic;
			//
			displayAsPassword = value.displayAsPassword;
			restrict = value.restrict;
		}
		
		
		
		
		override protected function layoutChildren():void
		{
			if(this.currentBackground)
			{
				this.currentBackground.visible = true;
				this.currentBackground.touchable = true;
				this.currentBackground.width = this.actualWidth;
				this.currentBackground.height = this.actualHeight;
			}
			
			if(this.currentIcon is IValidating)
			{
				IValidating(this.currentIcon).validate();
			}
			
			if(this.currentIcon)
			{
				this.currentIcon.x = this._paddingLeft;
				this.currentIcon.y = this._paddingTop + (this.actualHeight - this._paddingTop - this._paddingBottom - this.currentIcon.height) / 2;
				this.textEditor.x = this.currentIcon.x + this.currentIcon.width + this._gap;
				this.promptTextRenderer.x = this.currentIcon.x + this.currentIcon.width + this._gap;
			}
			else
			{
				this.textEditor.x = this._paddingLeft;
				this.promptTextRenderer.x = this._paddingLeft;
			}
			
			//trace(Starling.current.viewPort.height ,BSystem.screenHeight ,Starling.current.stage.stageHeight ,BSystem.screenHeight/Starling.current.stage.stageHeight);
			this.textEditor.y = this._paddingTop;
			this.textEditor.width = this.actualWidth - this._paddingRight - this.textEditor.x;
			this.textEditor.height = this.actualHeight - this._paddingTop - this._paddingBottom;
			
			this.promptTextRenderer.y = this._paddingTop;
			this.promptTextRenderer.width = this.actualWidth - this._paddingRight - this.promptTextRenderer.x;
			this.promptTextRenderer.height = this.actualHeight - this._paddingTop - this._paddingBottom;
		}
	}
}